package com.egg.auth.service.login;


import cn.hutool.core.util.ObjectUtil;
import com.egg.auth.enums.account.AccountTypeEnum;
import com.egg.auth.model.request.Login;
import com.egg.common.core.model.response.ResponseData;

import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

public interface ILoginFactory {


    Map<String, ILoginFactory> container = new ConcurrentHashMap<>();

    static Optional<ILoginFactory> findFactory(AccountTypeEnum accountType) {
        return findFactory(accountType.getCode());
    }

    static Optional<ILoginFactory> findFactory(String accountType) {
        if (ObjectUtil.isEmpty(accountType)) {
            return Optional.empty();
        }
        ILoginFactory service = ILoginFactory.container.get(accountType);
        return Optional.ofNullable(service);
    }

    /**
     * 登录
     *
     * @param login
     * @return token
     */
    ResponseData<String> login(Login login);

}
